<?php

/**
 * LEAGUEMan
 * 
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

?>

<script language="javascript">
	function savePlayermap( n ) {
		for ( var j = 0; j <= n; j++ ) {
			box = eval( "document.adminForm.cb" + j );
			if ( box ) {
				if ( box.checked == false ) {
					box.checked = true;
				}
				} else {
					alert("You cannot change the order of items, as an item in the list is `Checked Out`");
					return;
				}
			}
		submitform('savelist');
	}
</script>

<form action="index2.php" method="post" name="adminForm">
	<table cellpadding="4" cellspacing="0" border="0" width="100%">
		<tr>
			<td width="100%" class="sectionname">Playermap</td>
			<td nowrap="nowrap">
				<fieldset>
					<legend>Action</legend>
					<input type="submit" onclick="javascript: savePlayermap( <?php echo count( $this->rows ) - 1; ?> )" class="button" value="Save this List!"/>
					</fieldset>
			</td>
			<td nowrap="nowrap">
				<fieldset>
					<legend>Select a Team</legend>
					<?php echo mosHTML::selectList($this->team_list, '_team_', 'class="inputbox" size="1" onChange="javascript:submitbutton(\'change\');"', 'value', 'text', $this->teammap->getID());?>
				</fieldset>
			</td>
		</tr>
	</table>

	<table class="adminlist">
		<tr>
			<th width="1%">
				<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->rows ); ?>);" />
			</th>
			<th width="25%" class="title"><?php echo 'Player';?></th>
			<th width="59%"><?php echo 'Position';?></th>
			<th width="5%"><?php echo 'No.';?></th>
			
			<?php 
				
				foreach($this->project->getEventtypes() as $e){
					
					$eventtype = $this->eventtypemap->getEventtype($e);
				?>
					<th width="5%"><?php echo $eventtype->getIconImage();?></th>
				<?php
					
				}
				
			?>
			<th width="5%"><?php echo 'Action'?></th>
		</tr>
<?php
	$k = 1;
	$i = 0;
	foreach($this->rows as $row) {
		
		$pm = LM::getLMTable("Playermap2");
		$pm->populate($row);
		
  		$k = 1 - $k;
		
?>
		<tr class="<?php echo "row$k"; ?>">
			<td align="center">
				<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $pm->getID(); ?>" onclick="isChecked(this.checked);" />
      		</td>
			<td>
				<a href="#edit" onclick="return listItemTask('cb<?php echo $i;?>','edit')" onmouseover="this.T_DELAY=50;return escape('<b><?php echo $row->player_name;?></b>: Edit this Player!')">
					<?php echo $row->player_name; ?>
				</a>
			</td>
			<td align="center"><?php echo mosHTML::selectList( $this->positions, 'playermap_position[]', 'class="text_area" size="1"','value', 'text', $pm->getPosition() );; ?></td>
			<td align="center">
				<input type="text" name="position_number[]" size="4" value="<?php echo $pm->getNumber(); ?>" class="text_area" style="text-align: center" />
			</td>
			
			<?php 
				
				foreach($this->project->getEventtypes() as $e){
					
					$eventtype		= $this->eventtypemap->getEventtype($e);
					$association	= $eventtype->playermap_association;
				?>
					<td align="center">
						<input type="text" name="<?php echo $association;?>[]" size="4" value="<?php echo $pm->getCount($association); ?>" class="text_area" style="text-align: center" />
					</td>
				<?php
					
				}
				
			?>
			
			<td align="center">
				<a href="javascript: void(0);" title="unassign" onclick="javascript:if (confirm('Are you sure you want to unassign this item?')){return listItemTask('cb<?php echo $i;?>','unassign')}" onmouseover="this.T_DELAY=50;return escape('<b><?php echo $row->player_name;?></b>: Remove this Player from <br/> <b><?php echo $this->team->getName();?></b>!')">
					<img src="images/trash.png" width="12" height="12" border="0" alt="unassign" />
				</a>
			</td>
		</tr>
<?php
		$i++;
	} 
?>
	</table>
	<?php echo $this->pageNav->getListFooter(); ?>
	<input type="hidden" name="option" value="com_leagueman" />
	<input type="hidden" name="act" value="playermap" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
</form>